package cn.good.yan.b3;

import java.util.Arrays;

/**
 * 3 枚举
 *   案例：
 */
public class AEnum {

    // 启用状态（1启用；0 不启用）
    public enum IsUse {
        YES(1),
        NO(0);

        private final int index;

        IsUse(int index) {
            this.index = index;
        }

        public int getIndex() {
            return this.index;
        }
    }

    public enum State {
        DRAFT(0, "草稿"),
        VALID(2, "有效"),
        FINISH(3, "终止"),
        DELETE(4, "作废");
        private Integer index;
        private String name;
        State(Integer index, String name) {
            this.index = index;
            this.name = name;
        }
        public static String getName(Integer index) {
            for (AEnum.State c : AEnum.State.values()) {
                if (c.getIndex().equals(index)) {
                    return c.name;
                }
            }
            return null;
        }
        public static State getEnum(Integer index) {
            return Arrays.stream(values()).filter(t -> t.getIndex().equals(index)).findFirst().orElse(DRAFT);
        }
        public String getName() {
            return name;
        }
        public Integer getIndex() {
            return index;
        }
    }

    // 返回列表
//    public static void main(String[] args) {
//        List<DictionaryEntity> list = Lists.newArrayList();
//        for (AEnum.State u : AEnum.State.values()) {
//            list.add(new DictionaryEntity(u.getIndex(), u.getName()));
//        }
//        return R.ok(list);
//    }

}
